import { post, get } from '@/Api/request'
import { API_ENDPOINTS } from '@/config/api'

// 用户登录
export const login = (loginData: { username: string; password: string; captcha?: string; rememberMe?: boolean }) => {
  return post(API_ENDPOINTS.AUTH.LOGIN, loginData, {
    showLoading: true,
    loadingText: '登录中...'
  })
}

// 微信登录
export const wechatLogin = (loginData: { phone: string; code: string }) => {
  return post(API_ENDPOINTS.AUTH.WECHAT_LOGIN, loginData, {
    showLoading: true,
    loadingText: '微信登录中...'
  })
}

// 验证码登录
export const loginWithCode = (loginData: { phone: string; code: string }) => {
  return post(API_ENDPOINTS.AUTH.LOGIN_WITH_CODE, loginData, {
    showLoading: true,
    loadingText: '登录中...'
  })
}

// 发送验证码
export const sendCode = (phone: string) => {
  return post(API_ENDPOINTS.AUTH.SEND_CODE, { phone }, {
    showLoading: true,
    loadingText: '发送中...'
  })
}

// 用户注册
export const register = (userData: { phone: string; password: string; code: string }) => {
  return post(API_ENDPOINTS.AUTH.REGISTER, userData, {
    showLoading: true,
    loadingText: '注册中...'
  })
}

// 忘记密码
export const resetPassword = (resetData: { phone: string; newPassword: string; code: string }) => {
  return post(API_ENDPOINTS.AUTH.RESET_PASSWORD, resetData, {
    showLoading: true,
    loadingText: '重置中...'
  })
}

// 刷新token
export const refreshToken = () => {
  return post(API_ENDPOINTS.AUTH.REFRESH_TOKEN, {}, {
    showLoading: false
  })
}

// 退出登录
export const logout = () => {
  return post(API_ENDPOINTS.AUTH.LOGOUT, {}, {
    showLoading: true,
    loadingText: '退出中...'
  })
}

// 获取用户信息
export const getUserInfo = () => {
  return get(API_ENDPOINTS.USER.INFO, {}, {
    showLoading: false
  })
}

// 更新用户信息
export const updateUserInfo = (userData: any) => {
  return post(API_ENDPOINTS.USER.UPDATE, userData, {
    showLoading: true,
    loadingText: '更新中...'
  })
}

// 修改密码
export const changePassword = (passwordData: { oldPassword: string; newPassword: string }) => {
  return post(API_ENDPOINTS.USER.CHANGE_PASSWORD, passwordData, {
    showLoading: true,
    loadingText: '修改中...'
  })
}

// 获取待办事项
export const getTodoList = (params: { page: number; size: number }) => {
  return get(API_ENDPOINTS.TODO.LIST, params, {
    showLoading: true,
    loadingText: '加载中...'
  })
}

// 处理待办事项
export const handleTodo = (todoId: string, action: string) => {
  return post(API_ENDPOINTS.TODO.HANDLE, { todoId, action }, {
    showLoading: true,
    loadingText: '处理中...'
  })
}

// 获取待办详情
export const getTodoDetail = (todoId: string) => {
  return get(`${API_ENDPOINTS.TODO.DETAIL}/${todoId}`, {}, {
    showLoading: true,
    loadingText: '加载中...'
  })
}

// 获取最近文档
export const getRecentDocuments = (params: { page: number; size: number }) => {
  return get(API_ENDPOINTS.DOCUMENT.RECENT, params, {
    showLoading: true,
    loadingText: '加载中...'
  })
}

// 获取文档列表
export const getDocumentList = (params: { page: number; size: number; type?: string }) => {
  return get(API_ENDPOINTS.DOCUMENT.LIST, params, {
    showLoading: true,
    loadingText: '加载中...'
  })
}

// 获取文档详情
export const getDocumentDetail = (documentId: string) => {
  return get(`${API_ENDPOINTS.DOCUMENT.DETAIL}/${documentId}`, {}, {
    showLoading: true,
    loadingText: '加载中...'
  })
}

// 获取系统公告
export const getAnnouncements = (params: { page: number; size: number }) => {
  return get(API_ENDPOINTS.ANNOUNCEMENT.LIST, params, {
    showLoading: true,
    loadingText: '加载中...'
  })
}

// 获取公告详情
export const getAnnouncementDetail = (announcementId: string) => {
  return get(`${API_ENDPOINTS.ANNOUNCEMENT.DETAIL}/${announcementId}`, {}, {
    showLoading: true,
    loadingText: '加载中...'
  })
}
